package com.efast.dmom.mes.datahandlers.entity;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.efast.dmom.mes.bean.MbomRsBomItemAlternate;
import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.dao.entity.MbomRsBomItemAlternateDao;
import com.efast.dmom.mes.datahandlers.base.PartRelateDataHandler;
import com.efast.dmom.mes.entity.MbomRsBomItemAlternateEntity;
import com.efast.dmom.mes.util.BaseEntityDataUtil;

@Component
public class MbomRsBomItemAlternateDataHandler extends PartRelateDataHandler<MbomRsBomItemAlternate>{
	@Autowired
	private MbomRsBomItemAlternateDao mbomRsBomItemAlternateDao;
	
	@Override
	public ResultBean save(MbomRsBomItemAlternate obj) {
		ResultBean resultBean = new ResultBean();
		if(obj==null) {
			resultBean.setSuccess(false);
			resultBean.setMessage("paramater is null");
			return resultBean;
		}
		MbomRsBomItemAlternateEntity entity = obj.getInnerData();
		if(entity==null) {
			resultBean.setSuccess(false);
			resultBean.setMessage("paramater innerdata is null");
			return resultBean;
		}
		
		BaseEntityDataUtil.setBaseEntityData(entity);
		int save = mbomRsBomItemAlternateDao.save(entity);
		if(save>0) {
			resultBean.setSuccess(true);
		}else {
			resultBean.setSuccess(false);
			resultBean.setMessage("insert fail");
		}
		return resultBean;
	}

	@Override
	public ResultBean update(MbomRsBomItemAlternate obj) {
		ResultBean resultBean = new ResultBean();
		if(obj==null) {
			resultBean.setSuccess(false);
			resultBean.setMessage("paramater is null");
			return resultBean;
		}
		MbomRsBomItemAlternateEntity entity = obj.getInnerData();
		if(entity==null) {
			resultBean.setSuccess(false);
			resultBean.setMessage("paramater innerdata is null");
			return resultBean;
		}
		
		BaseEntityDataUtil.updateBaseEntityData(entity);
		int save = mbomRsBomItemAlternateDao.update(entity);
		if(save>0) {
			resultBean.setSuccess(true);
		}else {
			resultBean.setSuccess(false);
			resultBean.setMessage("insert fail");
		}
		return resultBean;
	}

	@Override
	public ResultBean delete(MbomRsBomItemAlternate obj) {
		ResultBean resultBean = new ResultBean();
		if(obj==null) {
			resultBean.setSuccess(false);
			resultBean.setMessage("paramater is null");
			return resultBean;
		}
		MbomRsBomItemAlternateEntity entity = obj.getInnerData();
		if(entity==null) {
			resultBean.setSuccess(false);
			resultBean.setMessage("paramater innerdata is null");
			return resultBean;
		}
		
		BaseEntityDataUtil.updateBaseEntityData(entity);
		int save = mbomRsBomItemAlternateDao.delete(entity);
		if(save>0) {
			resultBean.setSuccess(true);
		}else {
			resultBean.setSuccess(false);
			resultBean.setMessage("insert fail");
		}
		return resultBean;
	}

	@Override
	public ResultBean saveBatch(List<MbomRsBomItemAlternate> obj) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ResultBean updateBatch(List<MbomRsBomItemAlternate> obj) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ResultBean deleteBatch(List<MbomRsBomItemAlternate> obj) {
		return null;
	}

	@Override
	public MbomRsBomItemAlternate getById(long id) {
		MbomRsBomItemAlternateEntity entity = mbomRsBomItemAlternateDao.getById(id);
		if(entity!=null) {
			MbomRsBomItemAlternate mbomRsBomItemAlternate = new MbomRsBomItemAlternate();
			mbomRsBomItemAlternate.setInnerData(entity);
			return mbomRsBomItemAlternate;
		}
		return null;
	}

}
